Ext.namespace('VAS');

VAS.MenuAddWindow = function($config) {
	var _this = this;
    var form = new Ext.form.FormPanel({
    	title:'菜单新增',
	    labelWidth: 200,
	    labelAlign:'right',
	    minButtonWidth:40,
	    buttonAlign:'center',
	    url:'modifyPs.action',
	    frame:true,
		width:700,
		height:400,
		layout:'form',
	    items : [{
	    	xtype:'panel',
	    	bodyStyle:'padding-bottom:30px'
	    },{
    		id:'firstT',
	        xtype:'textfield',
	        fieldLabel:'菜单名',
	        name:'oldPassword',
	        allowBlank:false,
	      	blankText:'菜单名不能为空!',
	      	width:200,
	      	required:true
	    },{
	    	xtype:'textfield',
	      	fieldLabel: 'URL',
	      	id:'newPassword',
	      	name: 'newPassword',
	      	allowBlank:false,
	      	blankText:'URL不能为空!',
	      	width:200,
	      	bodyStyle:'padding-bottom:30px',
	      	required:true
	    },{
	    	xtype:'panel',
	    	layout:'column',
	    	items : [{
	    		 	columnWidth:.55,
		            layout: 'form',
		            items:[{
				    	xtype:'textfield',
				      	fieldLabel: '图标',
				      	id:'imgIcon',
				      	name: 'newPassword',
				      	labelWidth: 50,
				      	allowBlank:false,
				      	blankText:'图标不能为空!',
				      	width:150,
				      	required:true
		            }]
	    	},{
	    			columnWidth:.45,
		            layout: 'form',
		            items:[{
				    	xtype:'button',
				    	id:'chooseBt',
				    	text:"选择",
				      	width:40
		            }]
	    		}
	    		
	    	]
	    },
			new Ext.form.ComboBox({
				store: new Ext.data.Store({
						proxy: new Ext.data.HttpProxy({url:'http/combox.json'}),
						reader: new Ext.data.JsonReader({
							root:'data.encodeDict'
						}, [
							{name: 'encodeValue'},
							{name: 'encodeDesc'}
						])							
					}),
	            fieldLabel : '父菜单',
				name:'service.servSource',
				id:'service.servSource',
				emptyText: '全部',
				mode: 'remote',
				width:200,
				triggerAction: 'all',
				valueField: 'encodeValue',
				displayField: 'encodeDesc'
				//readOnly:"true",
			}),  
			new Ext.form.ComboBox({
				store: new Ext.data.Store({
						proxy: new Ext.data.HttpProxy({url:'http/combox.json'}),
						reader: new Ext.data.JsonReader({
							root:'data.encodeDict'
						}, [
							{name: 'encodeValue'},
							{name: 'encodeDesc'}
						])							
				}),
	            fieldLabel : '排序',
				name:'service.servSource',
				id:'service1',
				emptyText: '全部',
				mode: 'remote',
				width:200,
				triggerAction: 'all',
				valueField: 'encodeValue',
				displayField: 'encodeDesc'
				//readOnly:"true",
			})   
	    ],

	    
	  buttons: [{
	       text: '保存',
	       id:'save'
	   },{
	       text: '返回',
	       handler:function(){
				alert(1);
	       }
	   }]
	   
	});			
	
	
	var _form = form.getForm();
	Ext.getCmp('save').on('click',function(){
		if(_form.isValid()){
				_form.submit({
		              url: alert(_form.url),
					  waitTitle: '正在提交',
		              waitMsg: '正在向服务器发送请求',
		              clientValidation: true,
					  success :function(form,action){
							Ext.Msg.alert('提示','提交保存成功!',function(){ 
								_form.reset();
							});
					  },
					  failure :function(form,action){
							if(action.failureType == Ext.form.Action.CLIENT_INVALID){
								Ext.Msg.alert('提示','输入的信息不符合规格，请按照提示重新输入！');
							}else{
								alertFailure(action.result.data);
							}
					 }		
		        });
		  }
	});
	
    var chooser;
    
    var btn =  Ext.getCmp("chooseBt");
    
    function insertImage(data){
    	Ext.getCmp('imgIcon').setValue(data.url);
    	/*
    	Ext.DomHelper.append('images', {
    		tag: 'img', src: data.url, style:'margin:10px;visibility:hidden;'
    	}, true).show(true).frame();
    	btn.focus();*/
    };
	
   btn.on('click',function(){
    	if(!chooser){
    		chooser = new ImageChooser({
    			url:'http/img.json',
    			width:515,
    			height:350
    		});
    	}
    	chooser.show(btn.getEl(), insertImage);
    
    });

	
	
	
	var thisConfig = {
		closable : false,
		autoScroll : true,
		frame:false,
		items : form
	};
	var _config = $config || {};

	Ext.apply(_this, Ext.apply(thisConfig, _config));
	VAS.MenuAddWindow.superclass.constructor.call(_this);

};
Ext.extend(VAS.MenuAddWindow,VAS.BasicWindow,{

});


Ext.reg('menuadd-win',VAS.MenuAddWindow);

